home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / game / shoot / ADescentSrc.lha / descent / misc / fileutil.c < prev    next >
C/C++ Source or Header  |  1998-03-03  |  3KB  |  160 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: /usr/CVS/descent/misc/fileutil.c,v $
  15.  * $Revision: 1.1.1.1 $
  16.  * $Author: nobody $
  17.  * $Date: 1998/03/03 15:12:42 $
  18.  *
  19.  * utilities for file manipulation
  20.  * 
  21.  * $Log: fileutil.c,v $
  22.  * Revision 1.1.1.1  1998/03/03 15:12:42  nobody
  23.  * reimport after crash from backup
  24.  *
  25.  * Revision 1.1.1.1  1998/02/13  20:21:18  hfrieden
  26.  * Initial Import
  27.  *
  28.  * Revision 1.6  1995/10/30  11:09:51  allender
  29.  * use FILE, not CFILE on the write* routines
  30.  *
  31.  * Revision 1.5  1995/05/11  13:00:34  allender
  32.  * added write functions which swap bytes
  33.  *
  34.  * Revision 1.4  1995/05/04  20:10:38  allender
  35.  * remove include for fcntl
  36.  *
  37.  * Revision 1.3  1995/04/26  10:14:39  allender
  38.  * added byteswap header file
  39.  *
  40.  * Revision 1.2  1995/04/26  10:13:21  allender
  41.  *
  42.  * Revision 1.1  1995/03/30  15:02:34  allender
  43.  * Initial revision
  44.  *
  45. */
  46.  
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <sys/types.h>
  50.  
  51. #include "fileutil.h"
  52. #include "cfile.h"
  53. #include "fix.h"
  54. #include "byteswap.h"
  55.  
  56. int macfilelength(int fd)
  57. {
  58.     int cur_pos, end_pos;
  59.     
  60.     cur_pos = lseek(fd, 0, SEEK_CUR);
  61.     lseek(fd, 0, SEEK_END);
  62.     end_pos = lseek(fd, 0, SEEK_CUR);
  63.     lseek(fd, cur_pos, SEEK_SET);
  64.     return end_pos;
  65. }
  66.  
  67. byte read_byte(CFILE *fp)
  68. {
  69.     byte b;
  70.     
  71.     cfread(&b, sizeof(byte), 1, fp);
  72.     return b;
  73. }
  74.  
  75. short read_short_le(CFILE *fp)
  76. {
  77.     short s;
  78.     
  79.     cfread(&s, sizeof(short), 1, fp);
  80.     return (s);
  81. }
  82.  
  83. short read_short_swap(CFILE *fp)
  84. {
  85.     short s;
  86.     
  87.     cfread(&s, sizeof(short), 1, fp);
  88.     return swapshort(s);
  89. }
  90.  
  91. int read_int_le(CFILE *fp)
  92. {
  93.     uint i;
  94.     
  95.     cfread(&i, sizeof(uint), 1, fp);
  96.     return i;
  97. }
  98.  
  99. int read_int_swap(CFILE *fp)
  100. {
  101.     uint i;
  102.     
  103.     cfread(&i, sizeof(uint), 1, fp);
  104.     return swapint(i);
  105. }
  106.  
  107. fix read_fix_le(CFILE *fp)
  108. {
  109.     fix f;
  110.     
  111.     cfread(&f, sizeof(fix), 1, fp);
  112.     return f;
  113. }
  114.  
  115. fix read_fix_swap(CFILE *fp)
  116. {
  117.     fix f;
  118.     
  119.     cfread(&f, sizeof(fix), 1, fp);
  120.     return (fix)swapint((uint)f);
  121. }
  122.  
  123. int write_byte(FILE *fp, byte b)
  124. {
  125.     return (fwrite(&b, sizeof(byte), 1, fp));
  126. }
  127.  
  128. int write_short(FILE *fp, short s)
  129. {
  130.     return (fwrite(&s, sizeof(short), 1, fp));
  131. }
  132.  
  133. int write_short_swap(FILE *fp, short s)
  134. {
  135.     s = swapshort(s);
  136.     return (fwrite(&s, sizeof(short), 1, fp));
  137. }
  138.  
  139. int write_int(FILE *fp, int i)
  140. {
  141.     return (fwrite(&i,sizeof(int), 1, fp));
  142. }
  143.  
  144. int write_int_swap(FILE *fp, int i)
  145. {
  146.     i = swapint(i);
  147.     return (fwrite(&i,sizeof(int), 1, fp));
  148. }
  149.  
  150. int write_fix(FILE *fp, fix f)
  151. {
  152.     return (fwrite(&f, sizeof(fix), 1, fp));
  153. }
  154.  
  155. int write_fix_swap(FILE *fp, fix f)
  156. {
  157.     f = (fix)swapint((int)f);
  158.     return (fwrite(&f, sizeof(fix), 1, fp));
  159. }
  160.